home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Node / Node_Console.c < prev    next >
C/C++ Source or Header  |  1996-06-25  |  9KB  |  310 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.  
  7. #include <exec/exec.h>
  8. #include <intuition/intuition.h>
  9. #include <devices/console.h>
  10. #include <devices/conunit.h>
  11. #include <dos/dos.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/alib_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/console_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <clib/dos_protos.h>
  19.  
  20. #define NOTMAIN
  21. #define ClrSignal(s)  SetSignal(0,s)
  22.  
  23. #include "/common/types.h"
  24. #include "/common/defines.h"
  25. #include "/common/structures.h"
  26. #include "/common/strings.h"
  27.  
  28. #include "/library/hbbscommon_protos.h"
  29. #include "/library/hbbscommon_pragmas.h"
  30. #include "nodelibrary/hbbsnode_protos.h"
  31. #include "nodelibrary/hbbsnode_pragmas.h"
  32.  
  33. extern struct NodeData *N_ND;
  34. extern struct BBSGlobalData *BBSGlobal;
  35. extern struct Library *HBBSCommonBase;
  36. extern struct Library *HBBSNodeBase;
  37. extern struct TextFont *HBBSFont;
  38. extern struct TextAttr HBBS8066;
  39.  
  40. struct ColorSpec ScreenColors[] =
  41. {
  42. //       R     G     B
  43.    0, 0x00, 0x00, 0x00,
  44.    1, 0x0F, 0x00, 0x00,
  45.    2, 0x00, 0x0F, 0x00,
  46.    3, 0x0F, 0x0F, 0x00,
  47.    4, 0x00, 0x00, 0x0F,
  48.    5, 0x0F, 0x00, 0x0F,
  49.    6, 0x00, 0x0F, 0x0F,
  50.    7, 0x0F, 0x0F, 0x0F,
  51.   ~0, 0x00, 0x00, 0x00
  52. };
  53.  
  54. UWORD DriPens[] = {
  55.   0,7,6,1,4,6,0,0,7,0,7,4,!0 };
  56.  
  57. UBYTE ConWinTitle[160]; // not gonna be bigger!
  58. UBYTE ScreenName[30]; // as in, PubScreenName :-)
  59. //UWORD ZoomCoords[]={0,0,100,11};
  60.  
  61. /*
  62. void AbortConRead( void )
  63. {
  64.   if (N_ND->ConWaiting)
  65.   {
  66.     if (!CheckIO((struct IORequest*)N_ND->ConRead))
  67.     {
  68.       AbortIO((struct IORequest*)N_ND->ConRead);
  69.       WaitIO((struct IORequest*)N_ND->ConRead);
  70.     }
  71.     N_ND->ConWaiting=FALSE;
  72.   }
  73. }
  74.  
  75. void SendConReadData( void )
  76. {
  77.   if (N_ND->ConWaiting) AbortConRead();
  78.   N_ND->ConRead->io_Command  = CMD_READ;
  79.   N_ND->ConRead->io_Data     = (APTR)N_ND->ConBuffer;
  80.   N_ND->ConRead->io_Length   = N_ND->ConBufferLen;
  81.  
  82.   ClrSignal(1L << N_ND->ConRPort->mp_SigBit);
  83.   SendIO((struct IORequest*)N_ND->ConRead);
  84.   N_ND->ConWaiting=TRUE;
  85. }
  86.  
  87. void ConReadData(ULONG Length ) // make DAMN sure that length is NEVER more that the buffer size!
  88. {
  89.   if (N_ND->ConWaiting) AbortConRead();
  90.   N_ND->ConRead->io_Command  = CMD_READ;
  91.   N_ND->ConRead->io_Data     = (APTR)N_ND->ConBuffer;
  92.   N_ND->ConRead->io_Length   = Length;
  93.  
  94.   ClrSignal(1L << N_ND->ConRPort->mp_SigBit);
  95.   SendIO((struct IORequest*)N_ND->ConRead);
  96.   N_ND->ConWaiting=TRUE;
  97. }
  98.  
  99. void ConWaitData( void )
  100. {
  101.   if (!N_ND->ConWaiting) SendConReadData();
  102.   WaitIO((struct IORequest*)N_ND->ConRead);
  103.   N_ND->ConWaiting=FALSE;
  104.   N_ND->ConBytes=N_ND->ConRead->io_Actual;
  105. }
  106.  
  107. void ConWriteData(UBYTE *data,ULONG length)
  108. {
  109.   N_ND->ConWrite->io_Command  = CMD_WRITE;
  110.   N_ND->ConWrite->io_Data     = data;
  111.   N_ND->ConWrite->io_Length   = length;
  112.  
  113.   DoIO((struct IORequest *)N_ND->ConWrite);
  114. }
  115.  
  116. void ConWriteStr(UBYTE *data)
  117. {
  118.   N_ND->ConWrite->io_Command  = CMD_WRITE;
  119.   N_ND->ConWrite->io_Data     = data;
  120.   N_ND->ConWrite->io_Length   = -1;
  121.  
  122.   DoIO((struct IORequest *)N_ND->ConWrite);
  123. }
  124. */
  125.  
  126.  
  127. void CleanupNodeConsoleWin( void )
  128. {
  129.   // do everything in reverse order..
  130.  
  131.   if (N_ND->ConScr)
  132.   {
  133.     if (N_ND->ConWin)
  134.     {
  135.       if (!N_ND->NodeSettings.UseOwnScreen) // only save settings for window rather than a screen...
  136.       {
  137.         N_ND->ConX=N_ND->ConWin->LeftEdge;
  138.         N_ND->ConY=N_ND->ConWin->TopEdge;
  139.         N_ND->ConW=N_ND->ConWin->Width;
  140.         N_ND->ConH=N_ND->ConWin->Height;
  141.       }
  142.       if (N_ND->ConBuffer)
  143.       {
  144.         if (N_ND->ConRPort)
  145.         {
  146.           if (N_ND->ConWPort)
  147.           {
  148.             if (N_ND->ConWrite)
  149.             {
  150.               if (N_ND->ConRead)
  151.               {
  152.                 // remove any pending requests..
  153.                 if (N_ND->ConWaiting) AbortConRead();
  154.                 CloseDevice((struct IORequest*)N_ND->ConWrite);
  155.                 DeleteExtIO((struct IORequest*)N_ND->ConRead);
  156.               }
  157.               DeleteExtIO((struct IORequest*)N_ND->ConWrite);
  158.             }
  159.             DeletePort(N_ND->ConWPort);
  160.           }
  161.           DeletePort(N_ND->ConRPort);
  162.         }
  163.         FreeVec(N_ND->ConBuffer);
  164.       }
  165.       CloseWindow(N_ND->ConWin);
  166.     }
  167.     if (N_ND->NodeSettings.UseOwnScreen)
  168.     {
  169.  
  170.       while (!CloseScreen(N_ND->ConScr)); // *C* possible hang... changeme!
  171.     }
  172.     else
  173.     {
  174.       UnlockPubScreen(NULL,N_ND->ConScr);
  175.       N_ND->ConScr=NULL;
  176.     }
  177.   }
  178.   N_ND->ConWin=NULL;
  179.   N_ND->ConScr=NULL;
  180.   N_ND->ConOK=FALSE;
  181.   ScreenToFront(BBSGlobal->ScreenInfo.Scr); // put Main screen to front..
  182. }
  183.  
  184. void SetWatchTitles( void )
  185. {
  186.   sprintf(ConWinTitle,"Node %d ",N_ND->NodeNum);
  187.   if (N_ND->User.Valid)
  188.   {
  189.     sprintf(&ConWinTitle[strlen(ConWinTitle)],"%s %s (%s)",N_ND->User.CallData.Handle,N_ND->User.CallData.Group,N_ND->ConnectBaud);
  190.   }
  191.   if (N_ND->ConOK) SetWindowTitles(N_ND->ConWin,ConWinTitle,ConWinTitle); // set screen title
  192. }
  193.  
  194. V_BOOL OpenNodeConsoleWin( void )
  195. {
  196.   N_ND->ConOK=FALSE;
  197.   sprintf(ScreenName,"NodeWatch_%d",N_ND->NodeNum);
  198.   if (N_ND->NodeSettings.UseOwnScreen)
  199.   {
  200.     if (N_ND->ConScr=OpenScreenTags(NULL,
  201.                                 SA_Colors,  &ScreenColors[0],
  202.                                 SA_Pens,  &DriPens[0],
  203.                                 SA_Depth,N_ND->NodeSettings.ScrDepth,
  204.                                 SA_Left,0,
  205.                                 SA_Top,0,
  206.                                 SA_Width,N_ND->NodeSettings.ScrWidth,
  207.                                 SA_Height,N_ND->NodeSettings.ScrHeight,
  208.                                 SA_DisplayID,N_ND->NodeSettings.ScrModeID,
  209.                                 SA_Overscan,1,
  210.                                 SA_AutoScroll,1,
  211.                                 SA_Font, &HBBS8066,
  212. //                                SA_SysFont, 0,
  213.                                 SA_PubName,ScreenName,
  214.                                 TAG_DONE))
  215.     {
  216.       PubScreenStatus(N_ND->ConScr,0);
  217.     }
  218.  
  219.   }
  220.   else
  221.   {
  222.     N_ND->ConScr=LockPubScreen(BBSGlobal->ScreenInfo.PubScreenName);
  223.   }
  224.  
  225.   if (N_ND->ConScr)
  226.   {
  227.     if (N_ND->ConWin=OpenWindowTags(NULL,
  228.                                     WA_CustomScreen,N_ND->ConScr,
  229.                                     WA_Left,N_ND->NodeSettings.UseOwnScreen ? 0 : N_ND->ConX,
  230.                                     WA_Top,N_ND->NodeSettings.UseOwnScreen ? 11 : N_ND->ConY,
  231.                                     WA_Width,N_ND->NodeSettings.UseOwnScreen ? N_ND->NodeSettings.ScrWidth : N_ND->ConW,
  232.                                     WA_Height,N_ND->NodeSettings.UseOwnScreen ? N_ND->NodeSettings.ScrHeight-11 : N_ND->ConH,
  233.                                     WA_AutoAdjust,TRUE,
  234.                                     WA_MinWidth,200,
  235.                                     WA_MinHeight,50,
  236.                                     WA_MaxHeight,65534,
  237.                                     WA_MaxWidth,65534,
  238.                                     WA_BlockPen,7,
  239.                                     WA_DetailPen,0,
  240.                                     WA_Flags,N_ND->NodeSettings.UseOwnScreen ? WFLG_BORDERLESS|WFLG_BACKDROP|WFLG_ACTIVATE : WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET|WFLG_SIZEGADGET|WFLG_ACTIVATE,
  241.                                     WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE,
  242.                                     WA_SmartRefresh,TRUE,
  243.                                     TAG_DONE))
  244.     {
  245.       SetFont(N_ND->ConWin->RPort,HBBSFont);
  246.       if (N_ND->ConBuffer=AllocVec(DEF_CONBUFLEN,MEMF_PUBLIC))
  247.       {
  248.         N_ND->ConBufferLen=DEF_CONBUFLEN;
  249.         if (N_ND->ConRPort=CreatePort(0,0))
  250.         {
  251.           if (N_ND->ConWPort=CreatePort(0,0))
  252.           {
  253.             if (N_ND->ConWrite = (struct IOStdReq *) CreateExtIO(N_ND->ConWPort,(LONG)sizeof(struct IOStdReq)))
  254.             {
  255.               if (N_ND->ConRead = (struct IOStdReq *) CreateExtIO(N_ND->ConRPort,(LONG)sizeof(struct IOStdReq)))
  256.               {
  257.                 N_ND->ConWrite->io_Data = (APTR) N_ND->ConWin;
  258.                 N_ND->ConWrite->io_Length = sizeof(struct Window);
  259.  
  260.                 if (!(OpenDevice("console.device", CONU_SNIPMAP, (struct IORequest*)N_ND->ConWrite, 0)))
  261.                 {
  262.                   N_ND->ConRead->io_Device = N_ND->ConWrite->io_Device;
  263.                   N_ND->ConRead->io_Unit   = N_ND->ConWrite->io_Unit;
  264.                   N_ND->ConWaiting=FALSE;
  265.                   N_ND->ConOK=TRUE;
  266.                   SetWatchTitles();
  267.                   ScreenToFront(N_ND->ConScr); // put Console Screen to front..
  268.                   return(TRUE);
  269.                 }
  270.               }
  271.             }
  272.           }
  273.         }
  274.       }
  275.     }
  276.   }
  277.   CleanupNodeConsoleWin();
  278.   return(FALSE);
  279. }
  280.  
  281. void ChangeConsoleMode( short Mode )
  282. {
  283.   if (Mode==2)
  284.   {
  285.     if (N_ND->NodeSettings.UseOwnScreen) Mode=1; else Mode=0;
  286.   }
  287.   if (Mode==0) // use screen
  288.   {
  289.     if (!N_ND->NodeSettings.UseOwnScreen)
  290.     {
  291.       if (N_ND->ConOK) CleanupNodeConsoleWin();
  292.       // don't change the setting until the console window
  293.       // and or screen has been closed otherwise it will try to close
  294.       // the screen rather than unlocking it :-)
  295.       N_ND->NodeSettings.UseOwnScreen=TRUE;
  296.       OpenNodeConsoleWin();
  297.     }
  298.   }
  299.   if (Mode==1) // use window
  300.   {
  301.     if (N_ND->NodeSettings.UseOwnScreen)
  302.     {
  303.       if (N_ND->ConOK) CleanupNodeConsoleWin();
  304.       N_ND->NodeSettings.UseOwnScreen=FALSE;
  305.       OpenNodeConsoleWin();
  306.     }
  307.   }
  308. }
  309.  
  310.